import { defineStore } from 'pinia';

export const useSystemStore = defineStore('system', {
	state: () => {
		return { 
			capsuleInfo: {},
			systemInfo: {},
			leftToRightBian: 0, //胶囊左侧距离屏幕右侧距离
			menuTopToBar: 0, //胶囊距离状态栏间隔
			currentEnv: 'mini',
			version: "1.0.0",//记录当前项目版本
		 };
	},
	getters: {
		SDKVersion: state => state.systemInfo?.SDKVersion || '',
		statusBarHeight: state => state.systemInfo?.statusBarHeight || 0,
		screenWidth: state => state.systemInfo?.screenWidth || 0,
		screenHeight:state => state.systemInfo?.screenHeight || 0,
		capsuleWidth: state => state.capsuleInfo?.width || 0,
		capsuleHeight: state => state.capsuleInfo?.height || 0,
		capsuleTop: state => state.capsuleInfo?.top || 0,
		capsuleBottom: state => state.capsuleInfo?.bottom || 0,
		capsuleLeft: state => state.capsuleInfo?.left || 0,
		capsuleRight: state => state.capsuleInfo?.right || 0,
	},
	actions: {
		getSystemInfo() {
			const res = uni.getSystemInfoSync();
			console.log('信息---', res);	
			this.systemInfo=res;
			const {
				screenWidth,
				statusBarHeight
			} = res;
			//#ifndef H5
			let menuButtonInfo = uni.getMenuButtonBoundingClientRect();
			this.capsuleInfo=menuButtonInfo
			console.log('胶囊信息---', menuButtonInfo);
			const distance = screenWidth - menuButtonInfo.left;
			this.leftToRightBian=distance;
			const gapDistance = menuButtonInfo.top - statusBarHeight; //
			this.menuTopToBar=gapDistance;
			//#endif
			//#ifdef H5 || APP-PLUS
			this.currentEnv='h5OrApp'
			//#endif
		},
	 
	},
});